import {RequestOperate } from "../../opearte";
import   {OutputStream} from "../../stream";
import {getStringBinaryLength} from "../../utils";

export function  loginPacket(username:string,password:string){

    const buffer = new OutputStream(12+getStringBinaryLength(username)+getStringBinaryLength(password));

    buffer.writeInt( RequestOperate.LOGIN)

    buffer.writeString(username)
    buffer.writeString(password)


    return  buffer.buffer;
}
export function registerPacket(mobile:string,code:string){
    const buffer = new OutputStream(12+getStringBinaryLength(mobile)+getStringBinaryLength(code));

    buffer.writeInt( RequestOperate.REGISTER)

    buffer.writeString(mobile)
    buffer.writeString(code)


    return  buffer.buffer;
}



export function sendVerificationCodePacket(  mobile:string){
    const buffer = new OutputStream(12+getStringBinaryLength(mobile));

    buffer.writeInt( RequestOperate.SEND_VERIFICATION_CODE)

    buffer.writeString(mobile)



    return  buffer.buffer;

}

export function  realNameAuthenticationPacket(name:string,idNumber:string){
    const buffer = new OutputStream(12+getStringBinaryLength(name)+getStringBinaryLength(idNumber));

    buffer.writeInt( RequestOperate.REAL_NAME_AUTHENTICATION)

    buffer.writeString(name)
    buffer.writeString(idNumber)



    return  buffer.buffer;
}
export function channelLoginPacket(regionId:number,token:string){
    const buffer = new OutputStream(10+getStringBinaryLength(token));
    buffer.writeInt( RequestOperate.CHANNEL_LOGIN)
    buffer.writeShort(regionId)

    buffer.writeString(token)
    return buffer.buffer;


}

export function  simpleRequest(type:RequestOperate){
    const buffer = new OutputStream(4);

    buffer.writeInt(type)





    return  buffer.buffer;
}

export function  simpleShortRequest(type:RequestOperate,shortValue:number){
    const buffer = new OutputStream(6);


    buffer.writeInt(type)
    buffer.writeShort(shortValue)





    return  buffer.buffer;
}